package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.baihang.modeltag.BaihangModelTagRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百行联合建模标签
 *
 * @author guoqiang
 */

public class BaihangModelTagParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 百行联合建模标签
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BaihangModelTagRecord obj = (BaihangModelTagRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful);

        StringBuilder TxSb = new StringBuilder(500);
        TxSb.append(formatValue(obj.getErrorCode())).append(CRT001);
        TxSb.append(formatValue(obj.getErrorMessage())).append(CRT001);
        TxSb.append(formatValue(obj.getReportHeader_reportId())).append(CRT001);
        TxSb.append(formatValue(obj.getReportHeader_reportTime())).append(CRT001);
        TxSb.append(formatValue(obj.getReportHeader_queryResult())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_untilNow_2())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_realRepayment_D730_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_creditLimit_untilNow_min())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_creditLimit_D730_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_remainingAmount_untilNow_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_creditLimit_D365_min())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_loanAmount_D730_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_term_D730_max())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_creditLimit_D730_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_realRepayment_untilNow_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_realRepayment_D730_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_term_untilNow_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_loanAmount_D730_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_prepayment_D730_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_realRepayment_D180_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_realRepayment_D30_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_term_D730_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_realRepayment_D90_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_loanOrgCnt_untilNow())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_realRepayment_D180_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_creditLimit_D180_min())).append(CRT001);
        TxSb.append(formatValue(obj.getQ1Info_reason_D90_1())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_guaranteeTypeApplyCnt_untilNow_1())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_prepayment_untilNow_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_creditLimit_D730_min())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_untilNow_8())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_D730_8())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_guaranteeTypeLoanCnt_untilNow_1())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_D365_1_min())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_untilNow_1_min())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_untilNow_1_max())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_untilNow_1_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_untilNow_1_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_D730_1_min())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_D730_1_max())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_D730_1_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_guaranteeTypeCreditLimit_D730_1_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_untilNow_4())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_D730_2())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_D730_4())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_loanPurposeApplyCnt_untilNow_99())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_loanPurposeApplyCnt_untilNow_1())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_loanPurposeApplyCnt_untilNow_13())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_loanPurposeApplyCnt_D730_1())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_guaranteeTypeLoanStatus_untilNow_1_3())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_loanStatus_untilNow_3())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_loanStatus_D730_3())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D30_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D30_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D30_min())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D30_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D90_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D90_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D90_min())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D90_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D180_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D180_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D180_min())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D180_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D365_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D365_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D365_min())).append(CRT001);
        TxSb.append(formatValue(obj.getD3Cl2Info_overdueTerm_D365_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getQ1Info_orgTypeReason_D15_7_1())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusX2Account_D90_2())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusX2Account_D180_2())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusX2Account_D365_2())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusX2Account_D730_2())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusX2Account_D7_2())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusX2Account_D15_2())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusX2Account_D30_2())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_D365_2_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_D365_2_max())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_D365_2_min())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_D365_2_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_D730_2_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_D730_2_max())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_untilNow_2_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_untilNow_2_max())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_untilNow_2_min())).append(CRT001);
        TxSb.append(formatValue(obj.getX2Info_accntStatusCreditLimit_untilNow_2_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_orgTypeLoanCnt_untilNow_2())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_orgTypeLoanAmount_untilNow_2_sum())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_orgTypeLoanAmount_untilNow_2_max())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_orgTypeLoanAmount_untilNow_2_min())).append(CRT001);
        TxSb.append(formatValue(obj.getD2Cl1Info_orgTypeLoanAmount_untilNow_2_mean())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_D90_2())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_D180_2())).append(CRT001);
        TxSb.append(formatValue(obj.getA1Info_orgTypeApplyCnt_D365_2())).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + TxSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_baihang_model_tag_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIHANG_MODEL_TAG_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百行联合建模标签";
    }
}
